PROJECT_PATH = ..

SUB_PROJECT = $(PROJECT_PATH)/tools/inih

OUT_PATH := out

TARGET := svr

# target source
AR = ar
CC = gcc
CXX = g++


LIBS_DIR += -L./
# 依赖的库文件
LIBS += -lpthread

CFLAGS += -g -w

### 头文件路径
INC_DIR :=
INC_DIR += -I$(PROJECT_PATH)/
INC_DIR += -I$(PROJECT_PATH)/inc/
INC_DIR += -I$(PROJECT_PATH)/tools/

CFLAGS += $(LIBS_DIR) $(INC_DIR) $(LIBS)

### 子项目依赖
# .PHONY:sub_inih LIB_INIH
# sub_inih:
# 	make -C $(SUB_PROJECT)
LIB_STATIC := $(SUB_PROJECT)/out/inih.a


#### 源码路径
MAIN_FILE := qiandisk-svr.cpp

SRC_CPP := $(PROJECT_PATH)/src

### OBJ路径
OBJ_DIR := $(OUT_PATH)


### 目标文件
OBJ := $(patsubst $(SRC_CPP)/%.cpp,$(OBJ_DIR)/%.o, $(wildcard $(SRC_CPP)/*.cpp))
# $(info $(OBJ_CPP))


OBJ_MAIN := $(patsubst %.cpp,$(OBJ_DIR)/%.o, $(MAIN_FILE))

.PHONY:all
all: $(TARGET)

$(TARGET): $(OBJ)  $(OBJ_MAIN) $(LIB_STATIC)
	$(CXX) -o $@ $^ $(CFLAGS)

## 各个cpp的目标文件
$(OBJ_DIR)/%.o: $(SRC_CPP)/%.cpp
	$(CXX) -c $< -o $@ $(CFLAGS)

$(OBJ_MAIN): $(MAIN_FILE)
	$(CXX) -c $^ -o $@  $(CFLAGS)


.PHONY:clean
clean:
	rm $(OUT_PATH)/*
	rm $(TARGET)


